<h1>Listing blogs</h1>

<table border="1">
  <tr>
    <th>Title</th>
    <th>User</th>
    <th>Created at</th>
    <th>Updated at</th>
  </tr>
  
<% for blog in @blogs %>
  <tr>
    <td><%=link_to h(blog.title), blog_path(blog.user, blog) %> (<%= pluralize blog.articles.size, 'article' %>)</td>
    <td><%= link_to blog.user.login, user_url(blog.user) %></td>
    <td><%=h blog.created_at.to_formatted_s(:short) %></td>
    <td><%=h blog.updated_at.to_formatted_s(:short) %></td>
    <% if logged_in? && (current_user == blog.user || current_user.login == 'admin') %>
    <td><%= link_to 'Edit', edit_blog_path(blog.user, blog) %></td>
    <td><%= link_to 'Delete', blog_path(blog.user, blog), :confirm => 'Are you sure?', :method => :delete, :href => delete_blog_url(blog.user, blog)  %></td>
    <% end %>
  </tr>
<% end %>
</table>

<br />

<% if logged_in? %>
<%= link_to 'New blog', new_blog_path(current_user) %>
<% end %>
